package com.blog.mapper;

import com.blog.pojo.Tag;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TagMapper {

    /**
     * 查看所有标签
     * @return 标签列表
     */
    @Select("select * from tag")
    List<Tag> list();

    /**
     * 添加标签
     * @param tag 标签实体类
     */
    @Insert("insert into tag (tag_name) values (#{tagName})")
    void insert(Tag tag);

    /**
     * 删除标签
     * @param id 标签id
     */
    @Delete("delete from tag where id = #{id}")
    void deleteById(Integer id);

    /**
     * 删除标签时，删除掉文章标签关联表中的表项
     * @param id 标签id
     */
    @Delete("delete from article_tag where tag_id = #{id}")
    void deleteArticleTagByTagId(Integer id);

    /**
     * 删除标签时，删除掉爱好表中关联表项
     * @param id 标签id
     */
    @Delete("delete from hobby where tag_id = #{id}")
    void deleteHobbyByTagId(Integer id);
}